#!/usr/bin/make -f

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

export NO_PKG_MANGLE=1
export QA_RPATHS=$[ 0x0002 ]

DESTDIR = $(CURDIR)/debian/tmp

%:
	dh $@ --parallel --with autotools-dev,systemd

override_dh_auto_test:

override_dh_usrlocal:

override_dh_auto_configure:

override_dh_auto_build:
	export ASAN_OPTIONS=detect_leaks=0; unset LD_PRELOAD; \
		./config \
		no-asm \
		enable-camellia enable-seed enable-rfc3779 \
		enable-cms enable-md2 enable-rc5 \
		enable-weak-ssl-ciphers \
		enable-ssl3 enable-ssl3-method \
		shared zlib -g3 -O1 -DPURIFY \
		--prefix=/usr/local/openresty-asan/openssl111 \
		--libdir=lib \
		-I/usr/local/openresty-asan/zlib/include \
		-L/usr/local/openresty-asan/zlib/lib \
		-Wl,-rpath,/usr/local/openresty-asan/zlib/lib:/usr/local/openresty-asan/openssl111/lib
	make -j`nproc` \
		LD_LIBRARY_PATH= \
		CC="ccache gcc -fsanitize=address"

override_dh_auto_install:
	make install_sw DESTDIR=$(DESTDIR) \
		&& chmod +w $(DESTDIR)/usr/local/openresty-asan/openssl111/lib/*.so \
		&& chmod +w $(DESTDIR)/usr/local/openresty-asan/openssl111/lib/*/*.so \
		&& rm -rf $(DESTDIR)/usr/local/openresty-asan/openssl111/bin/c_rehash \
		&& rm -rf $(DESTDIR)/usr/local/openresty-asan/openssl111/lib/pkgconfig \
		&& rm -rf $(DESTDIR)/usr/local/openresty-asan/openssl111/misc

override_dh_auto_clean:
	dh_clean
	rm -rf $(DESTDIR)

override_dh_strip:
	dh_strip --dbg-package=openresty-openssl111-asan-dbgsym
